﻿using HealthcareSystem.API.Write.Application.Command.ChronicSignCommad;
using HealthcareSystem.Domain;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.Application.CommandHandel.ChronicSignCommadHandel
{

    public class DelCSignCommadHandel : IRequestHandler<DelCSignCommad, ApiResult<int>>
    {
        private readonly IBaseRepository<ChronicSign> delCS;

        public DelCSignCommadHandel(IBaseRepository<ChronicSign> DelCS)
        {
            delCS = DelCS;
        }

        public async Task<ApiResult<int>> Handle(DelCSignCommad request, CancellationToken cancellationToken)
        {
            ApiResult<int>  result=new ApiResult<int>();
            result.Code = ResultCode.Success;
            result.Message = "删除成功";

            var list = await delCS.GetByAsync(p => p.CSignId == request.CSignId);
            if(list.CSignIsdel == false)
            {
                list.CSignIsdel = true;
                await delCS.UpdAsync(list);
            }

            return await Task.FromResult(result); 
        }
    }
}
